package chatviews;

import interfaces.ChatView;

import java.util.Observer;
import java.util.Scanner;
import event.ObservableEvent;

public class ConsoleView implements ChatView {

	private String input;
	private ObservableEvent newInput = new ObservableEvent();

	public void waitForMessages() {

		new Thread(new Runnable() {
			public void run() {
				Scanner scanner = new Scanner(System.in);
				while (true) {

					input = scanner.nextLine();

					newInput.notifyEvent();
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}).start();

	}
 
	@Override
	public void showMessage(String message) {

		System.out.println(message);

	}

	@Override
	public String getInput() {
		return this.input;
	}

	@Override
	public void addNewInputListener(Observer observer) {
		this.newInput.addObserver(observer);
	}

}
